package com.google.p.code.springscim.openapi.v1;

import java.nio.charset.Charset;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import com.google.p.code.springscim.exception.ScimException;

public abstract class ScimWebUtils {
    
    public static ResponseEntity<ScimError> buildResponseEntity(ScimException exception) {
        ScimError scimError = new ScimError(exception.getCode(),
                                            exception.getMessage());
        
        HttpHeaders headers = new HttpHeaders();
        
        MediaType mediaType = new MediaType("application",
                                            "json",
                                            Charset.forName("UTF-8"));
        headers.setContentType(mediaType);
        
        return new ResponseEntity<ScimError>(scimError,
                                             headers,
                                             HttpStatus.valueOf(Integer.parseInt(scimError.getCode())));
    }
    
}
